
# third-party
import threading
import hashlib
import string

printLock = threading.Lock()
def threadPrint (*parameters):
	printLock.acquire()
	print string.join( map(str, parameters), " " )
	printLock.release()


def toByteString (bits):
	byteString = ""

	print bits
	
	for bit in bits:
		tank = []
		for i in range(8):
			if (ord(bit) >> i) & 1:
				tank.append("1")
			else:
				tank.append("0")
		tank.reverse()
		byteString += string.join( tank, "" ) + " "
	return byteString
	

def sha1 (target):
	hasher = hashlib.sha1()
	hasher.update( target )
	return hasher.digest()
